
const _interopRequireDefault = require('@babel/runtime/helpers/interopRequireDefault');

exports.__esModule = true;
exports.default = void 0;

const _babelHelperVueJsxMergeProps = _interopRequireDefault(require('@vue/babel-helper-vue-jsx-merge-props'));

const _utils = require('../utils');

const _functional = require('../utils/functional');

const _button = _interopRequireDefault(require('../button'));

const _radioGroup = _interopRequireDefault(require('../radio-group'));

const _Item = _interopRequireDefault(require('./Item'));

// Utils
// Components
const _createNamespace = (0, _utils.createNamespace)('address-list');
const createComponent = _createNamespace[0];
const bem = _createNamespace[1];
const t = _createNamespace[2];

function AddressList(h, props, slots, ctx) {
  function genList(list, disabled) {
    if (!list) {
      return;
    }

    return list.map((item, index) => h(_Item.default, {
      attrs: {
        data: item,
        disabled,
        switchable: props.switchable,
        defaultTagText: props.defaultTagText,
      },
      key: item.id,
      scopedSlots: {
        bottom: slots['item-bottom'],
      },
      on: {
        select: function select() {
          (0, _functional.emit)(ctx, disabled ? 'select-disabled' : 'select', item, index);

          if (!disabled) {
            (0, _functional.emit)(ctx, 'input', item.id);
          }
        },
        edit: function edit() {
          (0, _functional.emit)(ctx, disabled ? 'edit-disabled' : 'edit', item, index);
        },
        click: function click() {
          (0, _functional.emit)(ctx, 'click-item', item, index);
        },
      },
    }));
  }

  const List = genList(props.list);
  const DisabledList = genList(props.disabledList, true);
  return h('div', (0, _babelHelperVueJsxMergeProps.default)([{
    class: bem(),
  }, (0, _functional.inherit)(ctx)]), [slots.top == null ? void 0 : slots.top(), h(_radioGroup.default, {
    attrs: {
      value: props.value,
    },
  }, [List]), props.disabledText && h('div', {
    class: bem('disabled-text'),
  }, [props.disabledText]), DisabledList, slots.default == null ? void 0 : slots.default(), h('div', {
    class: bem('bottom'),
  }, [h(_button.default, {
    attrs: {
      round: true,
      block: true,
      type: 'danger',
      text: props.addButtonText || t('add'),
    },
    class: bem('add'),
    on: {
      click: function click() {
        (0, _functional.emit)(ctx, 'add');
      },
    },
  })])]);
}

AddressList.props = {
  list: Array,
  value: [Number, String],
  disabledList: Array,
  disabledText: String,
  addButtonText: String,
  defaultTagText: String,
  switchable: {
    type: Boolean,
    default: true,
  },
};

const _default = createComponent(AddressList);

exports.default = _default;
